#include "./FHttpExample.h"

#include "HttpModule.h"
#include "Interfaces/IHttpResponse.h"

void FHttpExample::SendGetRequest(const FString& Url)
{
	TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
	Request->SetURL(Url);
	Request->SetVerb("GET");
	// Request->SetHeader("Content-Type", "application/json");
	Request->SetHeader(TEXT("User-Agent"), TEXT("X-UnrealEngine-Agent"));
	Request->OnProcessRequestComplete().BindLambda(
		[Url](FHttpRequestPtr Request, FHttpResponsePtr Response, bool WasSuccessful)
		{
			if (Response->GetResponseCode() == 200)
			{
				UE_LOG(LogTemp, Warning, TEXT("请求 %s 成功：\n %s"), *Url, *Response->GetContentAsString());
			}
			else
				UE_LOG(LogTemp, Warning, TEXT("请求 %s 失败！"), *Url);
		});
	Request->ProcessRequest();
}
